/*
 * NewJFrame.java
 *
 * Created on 26 Март 2008 г., 22:16
 */

package my.engine.client.core;

import my.engine.client.forms.settings.SettingsForm;
import java.awt.BorderLayout;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeModel;
import my.engine.client.objects.FormObject;

/**
 *
 * @author  Администратор
 */
public class MainFrame extends javax.swing.JFrame {

    /** Creates new form NewJFrame */
    public MainFrame() {
        initComponents();
        customInitComponents();
    }

    private void customInitComponents() {
        DefaultMutableTreeNode root = new DefaultMutableTreeNode("Services");
        
        DefaultMutableTreeNode settings = new DefaultMutableTreeNode(new FormObject("Settings", new SettingsForm()));
        root.add(settings);
        TreeModel model = new DefaultTreeModel(root);
        servicesTree.setModel(model);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jSplitPane1 = new javax.swing.JSplitPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        servicesTree = new javax.swing.JTree();
        emptyContentPanel = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jSplitPane1.setDividerLocation(150);
        jSplitPane1.setDividerSize(3);

        servicesTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
            public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
                servicesTreeValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(servicesTree);

        jSplitPane1.setLeftComponent(jScrollPane1);

        emptyContentPanel.setLayout(new java.awt.BorderLayout());
        jSplitPane1.setRightComponent(emptyContentPanel);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 825, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 603, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void servicesTreeValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_servicesTreeValueChanged
       
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) servicesTree.getLastSelectedPathComponent();
        if (node == null) return;

        Object nodeInfo = node.getUserObject();
        if (node.isLeaf()) {
            FormObject form = (FormObject)nodeInfo;
            //emptyContentPanel.removeAll();
            emptyContentPanel.add(form.getServiceForm(), BorderLayout.CENTER);
            emptyContentPanel.updateUI();
        }
        
    }//GEN-LAST:event_servicesTreeValueChanged

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel emptyContentPanel;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JTree servicesTree;
    // End of variables declaration//GEN-END:variables

}
